home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevpsf.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  9.7 KB  |  276 lines

  1. /* Copyright (C) 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevpsf.h,v 1.7.2.1 2000/11/09 20:37:29 rayjj Exp $ */
  20. /* PostScript/PDF font writing interface */
  21.  
  22. #ifndef gdevpsf_INCLUDED
  23. #  define gdevpsf_INCLUDED
  24.  
  25. #include "gsccode.h"
  26.  
  27. /* ---------------- Embedded font writing ---------------- */
  28.  
  29. #ifndef gs_font_DEFINED
  30. #  define gs_font_DEFINED
  31. typedef struct gs_font_s gs_font;
  32. #endif
  33. #ifndef gs_font_base_DEFINED
  34. #  define gs_font_base_DEFINED
  35. typedef struct gs_font_base_s gs_font_base;
  36. #endif
  37.  
  38. /*
  39.  * Define the structure used for enumerating the glyphs in a font or a
  40.  * font subset.  This type is opaque to clients: we declare it here only
  41.  * so that clients can allocate it on the stack.
  42.  */
  43. typedef struct psf_glyph_enum_s psf_glyph_enum_t;
  44. struct psf_glyph_enum_s {
  45.     gs_font *font;
  46.     struct su_ {
  47.     union sus_ {
  48.         const gs_glyph *list;    /* if subset given by a list */
  49.         const byte *bits;    /* if CID or TT subset given by a bitmap */
  50.     } selected;
  51.     uint size;
  52.     } subset;
  53.     gs_glyph_space_t glyph_space;
  54.     ulong index;
  55.     int (*enumerate_next)(P2(psf_glyph_enum_t *, gs_glyph *));
  56. };
  57.  
  58. /*
  59.  * Begin enumerating the glyphs in a font or a font subset.  If subset_size
  60.  * > 0 but subset_glyphs == 0, enumerate all glyphs in [0 .. subset_size-1]
  61.  * (as integer glyphs, i.e., offset by gs_min_cid_glyph).
  62.  */
  63. void psf_enumerate_list_begin(P5(psf_glyph_enum_t *ppge, gs_font *font,
  64.                  const gs_glyph *subset_list,
  65.                  uint subset_size,
  66.                  gs_glyph_space_t glyph_space));
  67. /* Backward compatibility */
  68. #define psf_enumerate_glyphs_begin psf_enumerate_list_begin
  69.  
  70. /* Begin enumerating CID or TT glyphs in a subset given by a bit vector. */
  71. /* Note that subset_size is given in bits, not in bytes. */
  72. void psf_enumerate_bits_begin(P5(psf_glyph_enum_t *ppge, gs_font *font,
  73.                  const byte *subset_bits, uint subset_size,
  74.                  gs_glyph_space_t glyph_space));
  75. /* Backward compatibility */
  76. #define psf_enumerate_cids_begin(ppge, font, bits, size)\
  77.    psf_enumerate_bits_begin(ppge, font, bits, size, GLYPH_SPACE_NAME)
  78.  
  79. /*
  80.  * Reset a glyph enumeration.
  81.  */
  82. void psf_enumerate_glyphs_reset(P1(psf_glyph_enum_t *ppge));
  83.  
  84. /*
  85.  * Enumerate the next glyph in a font or a font subset.
  86.  * Return 0 if more glyphs, 1 if done, <0 if error.
  87.  */
  88. int psf_enumerate_glyphs_next(P2(psf_glyph_enum_t *ppge, gs_glyph *pglyph));
  89.  
  90. /*
  91.  * Get the set of referenced glyphs (indices) for writing a subset font.
  92.  * Does not sort or remove duplicates.
  93.  */
  94. int psf_subset_glyphs(P3(gs_glyph glyphs[256], gs_font *font,
  95.              const byte used[32]));
  96.  
  97. /*
  98.  * Add composite glyph pieces to a list of glyphs.  Does not sort or
  99.  * remove duplicates.  max_pieces is the maximum number of pieces that a
  100.  * single glyph can have: if this value is not known, the caller should
  101.  * use max_count.
  102.  */
  103. int psf_add_subset_pieces(P5(gs_glyph *glyphs, uint *pcount, uint max_count,
  104.                  uint max_pieces, gs_font *font));
  105.  
  106. /*
  107.  * Sort a list of glyphs and remove duplicates.  Return the number of glyphs
  108.  * in the result.
  109.  */
  110. int psf_sort_glyphs(P2(gs_glyph *glyphs, int count));
  111.  
  112. /*
  113.  * Return the index of a given glyph in a sorted list of glyphs, or -1
  114.  * if the glyph is not present.
  115.  */
  116. int psf_sorted_glyphs_index_of(P3(const gs_glyph *glyphs, int count,
  117.                   gs_glyph glyph));
  118. /*
  119.  * Determine whether a sorted list of glyphs includes a given glyph.
  120.  */
  121. bool psf_sorted_glyphs_include(P3(const gs_glyph *glyphs, int count,
  122.                   gs_glyph glyph));
  123.  
  124. /*
  125.  * Define the internal structure that holds glyph information for an
  126.  * outline-based font to be written.  Currently this only applies to
  127.  * Type 1, Type 2, and CIDFontType 0 fonts, but someday it might also
  128.  * be usable with TrueType (Type 42) and CIDFontType 2 fonts.
  129.  */
  130. typedef struct psf_outline_glyphs_s {
  131.     gs_glyph notdef;
  132.     gs_glyph subset_data[256 * 3 + 1]; /* *3 for seac, +1 for .notdef */
  133.     gs_glyph *subset_glyphs;    /* 0 or subset_data */
  134.     uint subset_size;
  135. } psf_outline_glyphs_t;
  136.  
  137. #ifndef gs_font_type1_DEFINED
  138. #  define gs_font_type1_DEFINED
  139. typedef struct gs_font_type1_s gs_font_type1;
  140. #endif
  141.  
  142. /* Define the type for the glyph data callback procedure. */
  143. typedef int (*glyph_data_proc_t)(P4(gs_font_base *, gs_glyph,
  144.                     gs_const_string *, gs_font_type1 **));
  145.  
  146. /* Check that all selected glyphs can be written. */
  147. int psf_check_outline_glyphs(P3(gs_font_base *pfont,
  148.                 psf_glyph_enum_t *ppge,
  149.                 glyph_data_proc_t glyph_data));
  150.  
  151. /*
  152.  * Gather glyph information for a Type 1, Type 2, or CIDFontType 0 font.
  153.  * Note that the glyph_data procedure returns both the outline string and
  154.  * a gs_font_type1 (Type 1 or Type 2) font: for Type 1 or Type 2 fonts,
  155.  * this is the original font, but for CIDFontType 0 fonts, it is the
  156.  * FDArray element.
  157.  */
  158. int psf_get_outline_glyphs(P5(psf_outline_glyphs_t *pglyphs,
  159.                   gs_font_base *pfont, gs_glyph *subset_glyphs,
  160.                   uint subset_size, glyph_data_proc_t glyph_data));
  161.  
  162. /* ------ Exported by gdevpsf1.c ------ */
  163.  
  164. /* Gather glyph information for a Type 1 or Type 2 font. */
  165. int psf_type1_glyph_data(P4(gs_font_base *, gs_glyph, gs_const_string *,
  166.                 gs_font_type1 **));
  167. int psf_get_type1_glyphs(P4(psf_outline_glyphs_t *pglyphs,
  168.                 gs_font_type1 *pfont,
  169.                 gs_glyph *subset_glyphs, uint subset_size));
  170.  
  171. /*
  172.  * Write out a Type 1 font definition.  This procedure does not allocate
  173.  * or free any data.
  174.  */
  175. #define WRITE_TYPE1_EEXEC 1
  176. #define WRITE_TYPE1_ASCIIHEX 2  /* use ASCII hex rather than binary */
  177. #define WRITE_TYPE1_EEXEC_PAD 4  /* add 512 0s */
  178. #define WRITE_TYPE1_EEXEC_MARK 8  /* assume 512 0s will be added */
  179. #define WRITE_TYPE1_POSTSCRIPT 16  /* don't observe ATM restrictions */
  180. #define WRITE_TYPE1_WITH_LENIV 32  /* don't allow lenIV = -1 */
  181. int psf_write_type1_font(P7(stream *s, gs_font_type1 *pfont, int options,
  182.                 gs_glyph *subset_glyphs, uint subset_size,
  183.                 const gs_const_string *alt_font_name,
  184.                 int lengths[3]));
  185.  
  186.  
  187. /* ------ Exported by gdevpsf2.c ------ */
  188.  
  189. /*
  190.  * Write out a Type 1 or Type 2 font definition as CFF.
  191.  * This procedure does not allocate or free any data.
  192.  */
  193. #define WRITE_TYPE2_NO_LENIV 1    /* always use lenIV = -1 */
  194. #define WRITE_TYPE2_CHARSTRINGS 2 /* convert T1 charstrings to T2 */
  195. #define WRITE_TYPE2_AR3 4    /* work around bugs in Acrobat Reader 3 */
  196. int psf_write_type2_font(P6(stream *s, gs_font_type1 *pfont, int options,
  197.                 gs_glyph *subset_glyphs, uint subset_size,
  198.                 const gs_const_string *alt_font_name));
  199.  
  200. #ifndef gs_font_cid0_DEFINED
  201. #  define gs_font_cid0_DEFINED
  202. typedef struct gs_font_cid0_s gs_font_cid0;
  203. #endif
  204.  
  205. /*
  206.  * Write out a CIDFontType 0 font definition as CFF.  The options are
  207.  * the same as for psf_write_type2_font.  subset_cids is a bit vector of
  208.  * subset_size bits (not bytes).
  209.  * This procedure does not allocate or free any data.
  210.  */
  211. int psf_write_cid0_font(P6(stream *s, gs_font_cid0 *pfont, int options,
  212.                const byte *subset_cids, uint subset_size,
  213.                const gs_const_string *alt_font_name));
  214.  
  215. /* ------ Exported by gdevpsfm.c ------ */
  216.  
  217. /*
  218.  * Write out a CMap in its customary (source) form.
  219.  */
  220. #ifndef gs_cmap_DEFINED
  221. #  define gs_cmap_DEFINED
  222. typedef struct gs_cmap_s gs_cmap_t;
  223. #endif
  224. typedef int (*psf_put_name_proc_t)(P3(stream *, const byte *, uint));
  225. int psf_write_cmap(P4(stream *s, const gs_cmap_t *pcmap,
  226.               psf_put_name_proc_t put_name,
  227.               const gs_const_string *alt_cmap_name));
  228.  
  229. /* ------ Exported by gdevpsft.c ------ */
  230.  
  231. /*
  232.  * Write out a TrueType (Type 42) font definition.
  233.  * This procedure does not allocate or free any data.
  234.  */
  235. #ifndef gs_font_type42_DEFINED
  236. #  define gs_font_type42_DEFINED
  237. typedef struct gs_font_type42_s gs_font_type42;
  238. #endif
  239. #define WRITE_TRUETYPE_CMAP 1    /* generate cmap from the Encoding */
  240. #define WRITE_TRUETYPE_NAME 2    /* generate name if missing */
  241. #define WRITE_TRUETYPE_POST 4    /* generate post if missing */
  242. #define WRITE_TRUETYPE_NO_TRIMMED_TABLE 8  /* not OK to use cmap format 6 */
  243. int psf_write_truetype_font(P6(stream *s, gs_font_type42 *pfont, int options,
  244.                    gs_glyph *subset_glyphs, uint subset_size,
  245.                    const gs_const_string *alt_font_name));
  246.  
  247. #ifndef gs_font_cid2_DEFINED
  248. #  define gs_font_cid2_DEFINED
  249. typedef struct gs_font_cid2_s gs_font_cid2;
  250. #endif
  251.  
  252. /*
  253.  * Write out a CIDFontType 2 font definition.  This procedure is identical
  254.  * to psf_write_truetype_font except that the subset, if any, is specified
  255.  * as a bit vector (as for psf_write_cid0_font) rather than a list of glyphs.
  256.  * NOTE: it is the client's responsibility to ensure that if the subset
  257.  * contains any composite glyphs, the components of the composites are
  258.  * included explicitly in the subset.
  259.  * This procedure does not allocate or free any data.
  260.  */
  261. int psf_write_cid2_font(P6(stream *s, gs_font_cid2 *pfont, int options,
  262.                const byte *subset_glyphs, uint subset_size,
  263.                const gs_const_string *alt_font_name));
  264.  
  265. /* ------ Exported by gdevpsfx.c ------ */
  266.  
  267. /*
  268.  * Convert a Type 1 CharString to (unencrypted) Type 2.
  269.  * This procedure does not allocate or free any data.
  270.  * NOTE: this procedure expands all Subrs in-line.
  271.  */
  272. int psf_convert_type1_to_type2(P3(stream *s, const gs_const_string *pstr,
  273.                   gs_font_type1 *pfont));
  274.  
  275. #endif /* gdevpsf_INCLUDED */
  276.